
//
//  XYBaseTableViewController.swift
//  SinaWeibo
//
//  Created by 韩啸宇 on 15/12/23.
//  Copyright © 2015年 backy. All rights reserved.
//

import UIKit

class XYBaseTableViewController: UITableViewController {

    /// 记录用户是否登录
    var isLogin = false
    /// 保存访客视图
    var visitorView: XYVisitorView?
    
    override func viewDidLoad() {

        // 1.判断用户是否登录, 判断显示什么view
        guard isLogin else {
            visitorView = XYVisitorView.visitorView()
            view = visitorView
            
            // 添加导航条按钮
            navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: Selector("registerBtnClick:"))
            navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: Selector("loginBtnClick:"))

            // 监听访客视图中登录注册按钮点击
            visitorView?.loginButton .addTarget(self, action: Selector("loginBtnClick:"), forControlEvents: UIControlEvents.TouchUpInside)
            visitorView?.registerButton.addTarget(self, action: Selector("registerBtnClick:"), forControlEvents: UIControlEvents.TouchUpInside)

            return
        }
        
        super.viewDidLoad()
    }
    
    // MARK: - 事件处理
    /**
    点击登录按钮
    */
    @objc private func loginBtnClick(sender: UIButton) {

        let sb = UIStoryboard(name: "OAuth", bundle: nil)
        let vc = sb.instantiateInitialViewController()!
        navigationController?.pushViewController(vc, animated: true)
        
        
    
//        navigationController?.pushViewController(vc, animated: true)
    }
    /**
    点击注册按钮
    */
    @objc private func registerBtnClick(sender: UIButton) {
        XYLog()
        
    }
}
